
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 12/26/2014 08:29:40
-- Generated from EDMX file: c:\WorkSpace\Git\Networkmall\Model\Networkmall.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Networkmall];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_目录商品]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[商品Set] DROP CONSTRAINT [FK_目录商品];
GO
IF OBJECT_ID(N'[dbo].[FK_商品订单]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[订单Set] DROP CONSTRAINT [FK_商品订单];
GO
IF OBJECT_ID(N'[dbo].[FK_订单物流信息]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[物流信息Set] DROP CONSTRAINT [FK_订单物流信息];
GO
IF OBJECT_ID(N'[dbo].[FK_购物车用户]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[购物车Set] DROP CONSTRAINT [FK_购物车用户];
GO
IF OBJECT_ID(N'[dbo].[FK_用户物流信息]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[物流信息Set] DROP CONSTRAINT [FK_用户物流信息];
GO
IF OBJECT_ID(N'[dbo].[FK_购物车商品]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[商品Set] DROP CONSTRAINT [FK_购物车商品];
GO
IF OBJECT_ID(N'[dbo].[FK_用户订单]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[订单Set] DROP CONSTRAINT [FK_用户订单];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[目录Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[目录Set];
GO
IF OBJECT_ID(N'[dbo].[商品Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[商品Set];
GO
IF OBJECT_ID(N'[dbo].[用户Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[用户Set];
GO
IF OBJECT_ID(N'[dbo].[物流信息Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[物流信息Set];
GO
IF OBJECT_ID(N'[dbo].[购物车Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[购物车Set];
GO
IF OBJECT_ID(N'[dbo].[订单Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[订单Set];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table '目录Set'
CREATE TABLE [dbo].[目录Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [目录编号] nvarchar(max)  NOT NULL,
    [目录名称] nvarchar(max)  NOT NULL,
    [目录描述] nvarchar(max)  NOT NULL
);
GO

-- Creating table '商品Set'
CREATE TABLE [dbo].[商品Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [商品编号] nvarchar(max)  NOT NULL,
    [商品名称] nvarchar(max)  NOT NULL,
    [商品描述] nvarchar(max)  NOT NULL,
    [商品图片] nvarchar(max)  NOT NULL,
    [添加时间] nvarchar(max)  NOT NULL,
    [商品出厂商] nvarchar(max)  NOT NULL,
    [商品出厂日期] nvarchar(max)  NOT NULL,
    [商品市价] nvarchar(max)  NOT NULL,
    [商品售价] nvarchar(max)  NOT NULL,
    [商品成本价] nvarchar(max)  NOT NULL,
    [商品详细名称] nvarchar(max)  NOT NULL,
    [商品简介] nvarchar(max)  NOT NULL,
    [购物车_Id] int  NOT NULL
);
GO

-- Creating table '用户Set'
CREATE TABLE [dbo].[用户Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [用户名称] nvarchar(max)  NOT NULL,
    [用户密码] nvarchar(max)  NOT NULL,
    [用户类型] nvarchar(max)  NOT NULL
);
GO

-- Creating table '物流信息Set'
CREATE TABLE [dbo].[物流信息Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [物流编号] nvarchar(max)  NOT NULL,
    [接货人姓名] nvarchar(max)  NOT NULL,
    [接货人邮编] nvarchar(max)  NOT NULL,
    [接货人国家] nvarchar(max)  NOT NULL,
    [接货人省份] nvarchar(max)  NOT NULL,
    [接货人所在城市] nvarchar(max)  NOT NULL,
    [接货人地址] nvarchar(max)  NOT NULL,
    [接货人电话] nvarchar(max)  NOT NULL,
    [发货人姓名] nvarchar(max)  NOT NULL,
    [发货人邮编] nvarchar(max)  NOT NULL,
    [发货人国家] nvarchar(max)  NOT NULL,
    [发货人省份] nvarchar(max)  NOT NULL,
    [发货人所在城市] nvarchar(max)  NOT NULL,
    [发货人地址] nvarchar(max)  NOT NULL,
    [发货人电话] nvarchar(max)  NOT NULL,
    [订单_Id] int  NOT NULL,
    [用户_Id] int  NOT NULL
);
GO

-- Creating table '购物车Set'
CREATE TABLE [dbo].[购物车Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [总价] nvarchar(max)  NOT NULL,
    [数量] nvarchar(max)  NOT NULL,
    [用户_Id] int  NOT NULL
);
GO

-- Creating table '订单Set'
CREATE TABLE [dbo].[订单Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [订单编号] nvarchar(max)  NOT NULL,
    [订单日期] nvarchar(max)  NOT NULL,
    [订单价格] nvarchar(max)  NOT NULL,
    [订单状态] nvarchar(max)  NOT NULL,
    [商品_Id] int  NOT NULL,
    [用户_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table '目录Set'
ALTER TABLE [dbo].[目录Set]
ADD CONSTRAINT [PK_目录Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '商品Set'
ALTER TABLE [dbo].[商品Set]
ADD CONSTRAINT [PK_商品Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '用户Set'
ALTER TABLE [dbo].[用户Set]
ADD CONSTRAINT [PK_用户Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '物流信息Set'
ALTER TABLE [dbo].[物流信息Set]
ADD CONSTRAINT [PK_物流信息Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '购物车Set'
ALTER TABLE [dbo].[购物车Set]
ADD CONSTRAINT [PK_购物车Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '订单Set'
ALTER TABLE [dbo].[订单Set]
ADD CONSTRAINT [PK_订单Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [商品_Id] in table '订单Set'
ALTER TABLE [dbo].[订单Set]
ADD CONSTRAINT [FK_商品订单]
    FOREIGN KEY ([商品_Id])
    REFERENCES [dbo].[商品Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_商品订单'
CREATE INDEX [IX_FK_商品订单]
ON [dbo].[订单Set]
    ([商品_Id]);
GO

-- Creating foreign key on [订单_Id] in table '物流信息Set'
ALTER TABLE [dbo].[物流信息Set]
ADD CONSTRAINT [FK_订单物流信息]
    FOREIGN KEY ([订单_Id])
    REFERENCES [dbo].[订单Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_订单物流信息'
CREATE INDEX [IX_FK_订单物流信息]
ON [dbo].[物流信息Set]
    ([订单_Id]);
GO

-- Creating foreign key on [用户_Id] in table '购物车Set'
ALTER TABLE [dbo].[购物车Set]
ADD CONSTRAINT [FK_购物车用户]
    FOREIGN KEY ([用户_Id])
    REFERENCES [dbo].[用户Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_购物车用户'
CREATE INDEX [IX_FK_购物车用户]
ON [dbo].[购物车Set]
    ([用户_Id]);
GO

-- Creating foreign key on [用户_Id] in table '物流信息Set'
ALTER TABLE [dbo].[物流信息Set]
ADD CONSTRAINT [FK_用户物流信息]
    FOREIGN KEY ([用户_Id])
    REFERENCES [dbo].[用户Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_用户物流信息'
CREATE INDEX [IX_FK_用户物流信息]
ON [dbo].[物流信息Set]
    ([用户_Id]);
GO

-- Creating foreign key on [购物车_Id] in table '商品Set'
ALTER TABLE [dbo].[商品Set]
ADD CONSTRAINT [FK_购物车商品]
    FOREIGN KEY ([购物车_Id])
    REFERENCES [dbo].[购物车Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_购物车商品'
CREATE INDEX [IX_FK_购物车商品]
ON [dbo].[商品Set]
    ([购物车_Id]);
GO

-- Creating foreign key on [用户_Id] in table '订单Set'
ALTER TABLE [dbo].[订单Set]
ADD CONSTRAINT [FK_用户订单]
    FOREIGN KEY ([用户_Id])
    REFERENCES [dbo].[用户Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_用户订单'
CREATE INDEX [IX_FK_用户订单]
ON [dbo].[订单Set]
    ([用户_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------